cssprovider: Use g_file_load_bytes()
authorBenjamin Otte <otte@redhat.com>
Mon, 5 Feb 2018 16:20:17 +0000 (17:20 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 5 Feb 2018 16:22:56 +0000 (17:22 +0100)
This way, we get a special no-copy case for resources.

https://bugzilla.gnome.org/show_bug.cgi?id=790270

gtk/gtkcssprovider.c

index 8a9a2d59feebcd60c3abc31e0c921ac3c2c97329..d4d865b68207136ad85517d05a49d0acd10ccd06 100644 (file)
@@ -1386,17 +1386,17 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
                                 const char     *text)
 {
   GtkCssScanner *scanner;
-  char *free_data = NULL;
+  GBytes *bytes;
 
   if (text == NULL)
     {
       GError *load_error = NULL;
 
-      if (g_file_load_contents (file, NULL,
-                                &free_data, NULL,
-                                NULL, &load_error))
+      bytes = g_file_load_bytes (file, NULL, NULL, &load_error);
+
+      if (bytes)
         {
-          text = free_data;
+          text = g_bytes_get_data (bytes, NULL);
         }
       else
         {
@@ -1428,6 +1428,10 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
             }
         }
     }
+  else
+    {
+      bytes = NULL;
+    }
 
   if (text)
     {
@@ -1445,7 +1449,8 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
         gtk_css_provider_postprocess (css_provider);
     }
 
-  g_free (free_data);
+  if (bytes)
+    g_bytes_unref (bytes);
 }
 
 /**